/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
  <file> uls_num.h </file>
  <brief>
    Recognizing the number tokens from input.
    This file is part of ULS, Unified Lexical Scheme.
  </brief>
  <author>
    Stanley J. Hong <babel96@gmail.com>, May 2011.
  </author>
*/
#ifndef __ULS_NUM_H__
#define __ULS_NUM_H__

#include "uls_type.h"

#ifdef __cplusplus
extern "C" {
#endif

// check the followins when the token by gettok() is toknum_NUMBER
#define ULS_NUM_FL_ERROR        0x01
#define ULS_NUM_FL_TOKBUF_USED  0x04

#define ULS_NUM_FL_MINUS    0x10
#define ULS_NUM_FL_ZERO     0x20
#define ULS_NUM_FL_FLOAT    0x40
#define ULS_NUM_FL_HEXA     0x80

/*
 * This function returns the end pointer of Hexa decimal string,
 *   which is got from scanning from *p_lptr to lptr_end.
 * The resultant (Hexa) string exists in input string by overwriting.
 * For example, in ret_ptr = uls_oct2hex_str(&lptr, lptr_end),
 *   the hexa-decimal string will be in [lptr, ret_ptr).
 */
int uls_oct2hex_str(uls_char_t** p_lptr, uls_char_t *lptr_end, uls_char_t* outbuf);

/*
 * This function transforms the number format to a standard form
 * The (input) number category of which this function suppots are
 *  decimal, octal, hexadecimal integer, or the scientific floating number.
 * For examples,
        '0' -----> 0
        '-0' -----> 0
        '-0.' -----> 0.
        '-0.314' -----> -.314
        '-.314' -----> -.314
        '314' -----> 314
        '-314' -----> -314
        '314.15' -----> .31415 E 3
        '-5041.7094' -----> -.50417094 E 4
        '314.15E-108' -----> .31415 E -105
        '-0.31415e303' -----> -.31415 E 303
        '.0050417094' -----> .50417094 E -2
        '0.031415e+1103' -----> .31415 E 1102
        '314.000' -----> .314 E 3
        '-3140000.000' -----> -.314 E 7
        '-50.0' -----> -.5 E 2
        '0.000' -----> 0.
        '-.000' -----> 0.
        '.000' -----> 0.
        '0xAF6' -----> 0xAF6
        '0x00AF6' -----> 0xAF6
        '-0x0AF6' -----> -0xAF6
        '0775' -----> 0x1FD
        '0000775' -----> 0x1FD
        '-000775' -----> -0x1FD
        '0' -----> 0
        '0.' -----> 0.
        '.0' -----> 0.
        '.' -----> NOT Number!
        '-0' -----> 0
        '-0.' -----> 0.
        '-.0' -----> 0.
        '-.' -----> NOT Number!
        '1.' -----> .1 E 1
        '.1' -----> .1
        '-1.' -----> -.1 E 1
        '-.1' -----> -.1
        '0.0' -----> 0.
        '1.0' -----> .1 E 1
        '0.1' -----> .1
        '1.1' -----> .11 E 1
        '-0.0' -----> 0.
        '-1.0' -----> -.1 E 1
        '-0.1' -----> -.1
        '-1.1' -----> -.11 E 1
 * Notice that prefix 'H' are prepended for hexadecimal numbers.
 */

uls_char_t* num2stdfmt_0(uls_char_t** p_lptr,
	int* p_flags, int *p_n1, uls_char_t** p_outbuf, int* p_outbuf_siz);

uls_char_t* num2stdfmt(uls_char_t** p_lptr,
	int* p_flags, int *p_n1, int* p_n2, int* p_expo);

int uls_dec2hex_str(uls_char_t* wrd, uls_char_t* outbuf);

#ifdef __cplusplus
}
#endif

#endif 
